/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cognitivetouch.colorSpan;

/**
 *
 * @author Xiaoxing
 */
public class Trial {

    private final TrialTimer timer;
    private float A;
    private final Judge judge;
    private boolean correct = false;
    private boolean judged = false;
    private float responseA;

    public Trial(Judge j) {
        judge = j;
        timer = new TrialTimer();
        timer.tagTrialStart();
        A = (float) Math.random() * 2 - 1;

    }

    public boolean executeToFinish() {
        switch (timer.getCurrentTask()) {
            case Fix:
                Fix.render(960, 540, A);
                return false;
            case Response:
                ColorWheel.render(960, 540);
                if (judged) {
                    Fix.render(960, 540, responseA);
                } else if ((!judged) && judge.judge() == Judge.judgeEvent.clickColor) {
                    responseA = judge.getA();
//                    Fix.render(960, 540, responseA);
                    if (Math.abs(responseA - A) < 0.25) {
                        correct = true;
                    }
                    judged = true;
                }
                return false;
            case Feedback:
                Feedback.render(correct);
                judge.judge();
                return false;
            case Finished:
                return true;
            default:
                return false;
        }
    }

}
